home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.4d7 source
/
tn3270
/
genattn.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-17
|
9KB
|
354 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.4d7 April, 1992
* Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include "maclib.h"
#define fileMenu 256
#define FILEID "attnmap.r.new"
char done; /* flag for mainline to return */
struct Rect screenRect, dragRect, pRect, sizeRect;
struct WindowRecord wRecord;
struct GrafPort *myWindow;
MenuHandle myMenus[1];
unsigned char * name1[32] =
{"PF1", "PF2", "PF3", "PF4", "PF5", "PF6",
"PF7", "PF8", "PF9", "PF10", "PF11", "PF12",
"PF13", "PF14", "PF15", "PF16", "PF17",
"PF18", "PF19", "PF20", "PF21", "PF22",
"PF23", "PF24", "Sys", "Clear", "PA1",
"PA2", "Erase", "Insert", "Delete", "Insert"};
unsigned char * name2[32] =
{"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"Req", "", "", "", "EOF", "Mode",
"Char", "Char"};
void macinit(void);
void hndmac(void);
void docommand(long mResult);
void defattn(char save);
void addtext(Rect *key, unsigned char *name1, unsigned char *name2);
main()
{
macinit(); /* general Mac initialization */
defattn(0);
done = 0;
while (!done) hndmac();
}
void macinit(void)
{
/* set-up general Macintosh environment */
InitGraf(&qd.thePort);
InitWindows();
InitFonts();
InitMenus();
InitDialogs(0L);
InitCursor();
myMenus[0] = NewMenu(fileMenu, "\pFile");
AppendMenu(myMenus[0], "\pSave");
AppendMenu(myMenus[0], "\pQuit");
InsertMenu(myMenus[0], 0);
DrawMenuBar();
screenRect = qd.screenBits.bounds;
SetRect(&dragRect, 4, 24, screenRect.right-4, screenRect.bottom-4);
pRect.top = 23;
pRect.left = 5;
pRect.bottom = 337;
pRect.right = 505;
sizeRect.top = 25;
sizeRect.left = 25;
sizeRect.bottom = 296;
sizeRect.right = 501;
myWindow = NewWindow(&wRecord, &pRect, "\pgenattn",
true, 3, (WindowPtr)-1L, 0, 0L);
SetPort(myWindow);
pRect = qd.thePort->portRect;
}
void hndmac(void)
{
short code;
unsigned short w, h;
long l;
struct EventRecord myEvent;
struct GrafPort *whichWindow;
/* handle system events */
SystemTask();
if (!GetNextEvent(everyEvent, &myEvent)) return;
switch(myEvent.what) {
case mouseDown:
code = FindWindow(myEvent.where, &whichWindow);
switch (code) {
case inMenuBar:
docommand(MenuSelect(myEvent.where));
break;
case inSysWindow:
SystemClick(&myEvent, whichWindow);
break;
case inDrag:
DragWindow(whichWindow, myEvent.where, &dragRect);
break;
case inGrow:
if (whichWindow == FrontWindow()) {
l = GrowWindow(whichWindow, myEvent.where,
&sizeRect);
h = l >> 16;
w = l & 0x0000ffffL;
SizeWindow(whichWindow, w, h, true);
}
break;
case inContent:
if (whichWindow != FrontWindow()) {
SelectWindow(whichWindow);
}
break;
}
break;
case mouseUp:
break;
case keyDown:
case autoKey:
break;
case activateEvt:
break;
case updateEvt:
BeginUpdate((WindowPtr)myEvent.message);
EndUpdate((WindowPtr)myEvent.message);
break;
default: break;
}
}
void docommand(long mResult)
{
short theItem, theMenu;
theMenu = mResult >> 16;
theItem = mResult;
switch(theMenu) {
case fileMenu:
switch (theItem) {
case 1: defattn(1);
done = 1;
break;
case 2: done = 1;
break;
default:
break;
}
break;
default:
break;
}
HiliteMenu(0);
}
void defattn(char save)
{
Rect mr;
Rect keyrect;
Rect framerect;
short i, j;
short fd, keynum;
unsigned char hexline[120];
unsigned char hexline2[120];
BitMap menumap;
GrafPtr currport;
unsigned char * bitptr;
mr.top = 40;
mr.left = 66;
mr.bottom = mr.top + 101;
mr.right = mr.left + 343;
/* entire menu (done by menu manager) */
framerect.top = mr.top - 1;
framerect.left = mr.left - 1;
framerect.bottom = mr.bottom + 1;
framerect.right = mr.right + 1;
FrameRect(&framerect);
/* pf1-12 */
framerect.top = mr.top + 1;
framerect.left = mr.left + 1;
framerect.bottom = mr.bottom - 1;
framerect.right = mr.left + 127;
FrameRect(&framerect);
keynum = 0;
keyrect.top = mr.top + 3;
keyrect.bottom = keyrect.top + 23;
for (i = 0; i < 4; i++) {
keyrect.left = mr.left + 3;
keyrect.right = keyrect.left + 40;
for (j=0; j < 3; j++) {
FrameRect(&keyrect);
addtext(&keyrect, name1[keynum], name2[keynum]);
keynum++;
keyrect.left += 41;
keyrect.right += 41;
}
keyrect.top += 24;
keyrect.bottom += 24;
}
/* pf13-24 */
framerect.top = mr.top + 1;
framerect.left = mr.left + 216;
framerect.bottom = mr.bottom - 1;
framerect.right = mr.left + 342;
FrameRect(&framerect);
keyrect.top = mr.top + 3;
keyrect.bottom = keyrect.top + 23;
for (i = 0; i < 4; i++) {
keyrect.left = mr.left + 218;
keyrect.right = keyrect.left + 40;
for (j=0; j < 3; j++) {
FrameRect(&keyrect);
addtext(&keyrect, name1[keynum], name2[keynum]);
keynum++;
keyrect.left += 41;
keyrect.right += 41;
}
keyrect.top += 24;
keyrect.bottom += 24;
}
/* special keys */
framerect.top = mr.top + 1;
framerect.left = mr.left + 129;
framerect.bottom = mr.bottom - 1;
framerect.right = mr.left + 214;
FrameRect(&framerect);
keyrect.top = mr.top + 3;
keyrect.bottom = keyrect.top + 23;
for (i = 0; i < 4; i++) {
keyrect.left = mr.left + 131;
keyrect.right = keyrect.left + 40;
for (j=0; j < 2; j++) {
FrameRect(&keyrect);
addtext(&keyrect, name1[keynum], name2[keynum]);
keynum++;
keyrect.left += 41;
keyrect.right += 41;
}
keyrect.top += 24;
keyrect.bottom += 24;
}
if (save == 0) return;
bitptr = (unsigned char *)NewPtr(4448L);
menumap.baseAddr = (Ptr)bitptr;
for (i=0; i < 4448; i++) *(bitptr + i) = 0;
menumap.rowBytes = 44;
menumap.bounds.top = 0;
menumap.bounds.left = 0;
menumap.bounds.bottom = mr.bottom - mr.top;
menumap.bounds.right = mr.right - mr.left;
GetPort(&currport);
CopyBits(&(currport->portBits), &menumap, &mr, &(menumap.bounds),
srcCopy, 0L);
fd = open(FILEID, O_CREAT+O_WRONLY);
write(fd, "data 'MMAP' (256, preload) {\n", 29);
for (i=0; i < 4448; i+= 16) {
sprintf(hexline, "\t$\"%02x%02x %02x%02x %02x%02x %02x%02x",
*(bitptr+i), *(bitptr+i+1),
*(bitptr+i+2), *(bitptr+i+3),
*(bitptr+i+4), *(bitptr+i+5),
*(bitptr+i+6), *(bitptr+i+7));
sprintf(hexline2, " %02x%02x %02x%02x %02x%02x %02x%02x\"\n",
*(bitptr+i+8), *(bitptr+i+9),
*(bitptr+i+10), *(bitptr+i+11),
*(bitptr+i+12), *(bitptr+i+13),
*(bitptr+i+14), *(bitptr+i+15));
strcat(hexline, hexline2);
for (j=0; j < strlen(hexline); j++) {
hexline[j] = toupper(hexline[j]);
}
write(fd, hexline, strlen(hexline));
}
write(fd, "};\n", 3);
close(fd);
DisposPtr(bitptr);
}
void addtext(Rect *key, unsigned char *name1, unsigned char *name2)
{
short w;
TextFont(3);
c2pstr(name1);
c2pstr(name2);
if (name2[0] == 0) {
TextSize(12);
w = StringWidth(name1);
if (w > 38) w = 38;
w = (38-w)/2;
MoveTo((*key).left+w+1, (*key).bottom-7);
DrawString(name1);
}
else {
TextSize(9);
w = StringWidth(name1);
if (w > 38) w = 38;
w = (38-w)/2;
MoveTo((*key).left+w+1, (*key).bottom-13);
DrawString(name1);
w = StringWidth(name2);
if (w > 38) w = 38;
w = (38-w)/2;
MoveTo((*key).left+w+1, (*key).bottom-4);
DrawString(name2);
}
p2cstr(name1);
p2cstr(name2);
}